package com.chukun.spring.beans.factory;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

public class DefaultUserFactory implements UserFactory, InitializingBean, DisposableBean {

    /**
     * 使用@PostConstruct注解，实现初始化
     */
    @PostConstruct
    public void init() {
        System.out.println("UserFactory init.....");
    }

    /**
     * 自定义初始化的方式实现，实现初始化
     */
    public void initUserFactory() {
        System.out.println("UserFactory initUserFactory .....");
    }

    /**
     * 实现InitializingBean接口，实现初始化
     * @throws Exception
     */
    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("UserFactory InitializingBean interface ....");
    }

    /**
     * 使用@PreDestroy，实现销毁操作
     */
    @PreDestroy
    public void destory() {
        System.out.println("UserFactory destory.....");
    }

    /**
     * 使用自定义方法，实现销毁操作
     */
    public void userDefineDestory() {
        System.out.println("UserFactory userDefineDestory.....");
    }

    /**
     * 实现DisposableBean接口，实现销毁操作
     */
    @Override
    public void destroy() throws Exception {
        System.out.println("UserFactory DisposableBean.....");
    }
}
